/**
 * 
 */
package com.ssm.controller.admin;

import java.util.Enumeration;
import java.util.Map;

import javax.accessibility.AccessibleRelation;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.controller.SSMController;
import com.ssm.exception.ExceptionCode;
import com.ssm.exception.SsmException;
import com.ssm.model.bean.SsmApi;
import com.ssm.model.mapper.ActionMapper;
import com.ssm.model.mapper.ApiMapper;
import com.ssm.model.mapper.WebSettingMapper;

/**
 * 
 * @author 危文涛<245108903@qq.com>
 * @version 2016年2月6日 下午1:27:13
 *
 */
@Controller
@RequestMapping(value="api")
public class ApiController extends AdminBaseController<SsmApi> {
	
	@RequestMapping(value="index")
	public String index(HttpServletRequest request)
	{
		request.setAttribute("WEB_TITLE","API接口列表");
		System.out.println("dwadw");
		this.List2Table(ApiMapper.class,null,request,false);
		
		return "api/index";
	}
	
	@RequestMapping(value="edit")
	public String edit(HttpServletRequest request,SsmApi api)
	{
		ApiMapper apiMapper=M.getMapper(ApiMapper.class);
		if(request.getMethod()=="POST")//添加&编辑API信息
		{
			if(api.getId()==null)//添加
			{
				api.setUserid(this.getUserID(request));
				api.setCreatetime(nowTime().toString());
				apiMapper.insert(api);
				request.setAttribute("item",api);
				request.setAttribute("WEB_TITLE","查看API接口");
			}
			else//编辑
			{
				apiMapper.updateByPrimaryKeySelective(api);
				return "redirect:index";
			}
		}
		else//查看API信息&显示API界面
		{
			Integer id=request.getParameter("id")==null?null:Integer.parseInt(request.getParameter("id"));
			if(id==null)//显示API界面
			{
				request.setAttribute("WEB_TITLE","添加API接口");
			}
			else//查看API信息
			{
				api=apiMapper.selectByPrimaryKey(id);
				request.setAttribute("item",api);
				request.setAttribute("WEB_TITLE","编辑API接口");
			}
		}
		return "api/edit";
	}
	@RequestMapping(value="changeStatus")
	public String changeStatus(HttpServletRequest request)
	{
		changeStatus(ApiMapper.class,request);
		return "redirect:index";
	}

}
